﻿/*

  The contents of this file are subject to the Mozilla Public License Version
  1.1 (the "License"); you may not use this file except in compliance with
  the License. You may obtain a copy of the License at 
  
           http://www.mozilla.org/MPL/ 
  
  Software distributed under the License is distributed on an "AS IS" basis,
  WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  for the specific language governing rights and limitations under the License. 
  
  The Original Code is LunAS Library.
  
  The Initial Developer of the Original Code is
  ALCARAZ Marc (aka eKameleon)  <ekameleon@gmail.com>.
  Portions created by the Initial Developer are Copyright (C) 2004-2010
  the Initial Developer. All Rights Reserved.
  
  Contributor(s) :
  Nicolas Surian (aka NairuS) <nicolas.surian@gmail.com> 
*/

package examples 
{
    import graphics.geom.EdgeMetrics;

    import lunas.display.text.VisualTextInput;
    import lunas.display.text.VisualTextInputStyle;
    import lunas.events.ComponentEvent;

    import flash.display.MovieClip;
    import flash.display.Sprite;
    import flash.display.StageScaleMode;
    import flash.events.Event;
    import flash.events.FocusEvent;
    import flash.text.TextFormat;

    public dynamic class ExampleVisualTextInput extends Sprite 
    {
        public function ExampleVisualTextInput()
        {
            stage.scaleMode = StageScaleMode.NO_SCALE ;
            
            var format:TextFormat = new TextFormat("Arial", 11) ;
            format.leftMargin     = 4 ;
            format.rightMargin    = 4 ;
            
            var style:VisualTextInputStyle = new VisualTextInputStyle( { color : 0xEFEE3A } ) ;
            
            var input1:VisualTextInput = new VisualTextInput( getChildByName( "skin1" ) as MovieClip ) ;
            var input2:VisualTextInput = new VisualTextInput( getChildByName( "skin2" ) as MovieClip ) ;
            
            // input1 behaviours
            
            input1.defaultTextFormat = format ;
            input1.tabIndex  = 1 ;
            input1.groupName = "group_input" ;
            input1.style = style ;
            input1.border    = new EdgeMetrics(4, 0, 4, 2) ;
            input1.addEventListener( ComponentEvent.ENTER  , debug ) ;
            input1.addEventListener( FocusEvent.FOCUS_IN   , debug ) ;
            input1.addEventListener( FocusEvent.FOCUS_OUT  , debug ) ;
            
            // input2 behaviours
            
            input2.defaultTextFormat = format ;
            
            input2.tabIndex  = 2 ;
            input2.groupName = "group_input" ;
            
            input2.addEventListener( ComponentEvent.ENTER  , debug ) ;
            input2.addEventListener( FocusEvent.FOCUS_IN  , debug ) ;
            input2.addEventListener( FocusEvent.FOCUS_OUT , debug ) ;
            
            addChild( input1 ) ;
            addChild( input2 ) ;
            
            input2.tabManager.select( "group_input" ) ;
            
//             input2.tabManager.unSelect() ;
            
            // tests
            
            // var style:VisualTextInputStyle = new VisualTextInputStyle() ;
//            input1.style = style ;
            
            // input1.displayAsPassword = true ;
            input1.htmlText = "<p>Hello <b>World</b></p>" ;
//            input1.restrict = "a-z 1-9" ;
//            input1.editable = false ;
//            input1.enabled  = false ;
        }
        
        public function debug( e:Event ):void
        {
            trace( e + " : " + e.target + " : " + e.currentTarget  ) ;
        }
    }
}